#ifndef _COMMON_LIBRARY_TYPE_H
#define _COMMON_LIBRARY_TYPE_H

#include "common_defs.h"

// library types
enum LibraryType {
	tFUNCTIONS,
	tCONFIG,
	tPICTURE,
	tSOUND,
	tVIDEO
};

#define LIB_NUM_TYPES 5

#define TYPE2ID(t) ((t)<<28)
#define ID2TYPE(id) ((id)>>28)

// library id of typed libraries
#define ID_LIBRARY_FUNCTIONS	TYPE2ID(tFUNCTIONS)
#define ID_LIBRARY_CONFIG		TYPE2ID(tCONFIG)
#define ID_LIBRARY_PICTURE		TYPE2ID(tPICTURE)
#define ID_LIBRARY_SOUND		TYPE2ID(tSOUND)
#define ID_LIBRARY_VIDEO		TYPE2ID(tVIDEO)

// config interface (for tCONFIG libraries)
struct sCInterface {	// open has to return a pointer to a user conf descriptor, each other function of this interface will be called with this pointer
	void *	(*open)			(FILE *fd, u8 idx_ext);	// has to return NULL on fail

// each function must return 0 on success
	int		(*get_first)	(void *confd, char **section, char **param, char **value);
	int		(*get_next)		(void *confd, char **section, char **param, char **value);

	int		(*get_string)	(void *confd, char *section, char *param, char **value);
	int		(*get_bool)		(void *confd, char *section, char *param, bool *value);
	int		(*get_integer)	(void *confd, char *section, char *param, s32 *value);
	int		(*get_float)	(void *confd, char *section, char *param, float *value);

	int		(*set_string)	(void *confd, char *section, char *param, char *value);
	int		(*set_bool)		(void *confd, char *section, char *param, bool value);
	int		(*set_integer)	(void *confd, char *section, char *param, s32 value);
	int		(*set_float)	(void *confd, char *section, char *param, float value);

	int		(*unset)		(void *confd, char *section, char *param);

	int		(*save)			(void *confd, FILE *fd);
	void	(*close)		(void *confd);
};

// picture interface (for tPICTURE libraries)
struct sPInterface {
	int (*decode)	(sPicture *img, FILE *fd, u8 idx_ext);
	int (*encode)	(sPicture *img, FILE *fd, u8 idx_ext);
};

// sound interface (for tSOUND libraries)
struct sSInterface {	// each function returns 0 on success; and something else on fail !
	int (*assign)		(FILE *f, u8 idx_ext);
	int (*getInfos)		(sSInfos *i);
	int (*getTags)		(sSTags *t);
	int (*setTags)		(sSTags *);
	int (*play)			();
	int (*pause)		();
	int (*stop)			();
	int (*seek)			(s32 r, u8 p);	// 'r' is the relative position (the unit is the unit of the position variable in sSInfos); 'p' is the start position (START, CUR, END)
	u32 (*position2ms)	(u32);
	u32 (*ms2position)	(u32);
	int (*deassign)		();
};

#endif

